﻿<!DOCTYPE html>
<!--考试记录管理编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{ExaminationRecord.TrainingCoursewareName+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.trainRecordId" slot="suffix"
                                           :placeholder="ExaminationRecord.TrainingCoursewareName">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in TrainingCoursewareName" :label="item.mark03"
                                               :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <el-form-item>
                        <div class="elst-select-mini">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ExaminationRecord.ExaminationDate+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.examinationDate" type="date" size="mini"
                                                format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择时间">
                                </el-date-picker>
                            </el-input>
                        </div>
                    </el-form-item>
                </el-col>

                <el-col :span="11">

                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{"承包商"+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.cbsListId" slot="suffix"
                                           :placeholder="ExaminationRecord.ExaminationCategory" @change="postChange2">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in CBS_Lists" :label="item.contractorName"
                                               :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{ExaminationRecord.Examiner+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.examiner" slot="suffix"
                                           :placeholder="ExaminationRecord.Examiner">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in Examiner" :label="item.personnelName" :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{ExaminationRecord.DegreeOfDifficulty+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.degreeOfDifficulty" slot="suffix"
                                           :placeholder="ExaminationRecord.DegreeOfDifficulty">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in DegreeOfDifficulty" :label="item.value" :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>




                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <div class="el-input el-input--mini el-input-group el-input-group--prepend">
                            <div class="el-input-group__prepend">
                                {{ExaminationRecord.Fraction+mark.m}}
                            </div>
                            <div>
                                <el-input-number class="el-input__inner" v-model="Form.fraction" @change="handleChange"
                                                 :min="0" size="mini">
                                </el-input-number>
                            </div>
                        </div>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{ExaminationRecord.IsPassed+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.isQualified" slot="suffix"
                                           :placeholder="ExaminationRecord.IsPassed">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in IsPassed" :label="item.value" :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>

            <el-row>

                <el-col span="9">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.attachmentName" autocomplete="off" size="mini" disabled="true">
                                <template slot="prepend">
                                    {{ExaminationRecord.Annex+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col span="4">
                    <el-upload name="files" class="fl" ref="Attachmentupload" action="/api/File/UploadFile"
                               :before-upload="beforeUpload" :on-success="successUpLoad" :auto-upload="true"
                               :show-file-list="false">
                        <el-button type="primary">{{col.lawUploadAttachment}}</el-button>
                    </el-upload>
                    <!--<el-upload class="upload-demo" ref="Attachmentupload" action="/api/File/UpdateFile" multiple="true"
                :on-preview="handlePreview" :on-remove="handleRemove"
                :before-upload="fileAttachmentUploadbeforeupload" :auto-upload="true" :limit="1"
                :show-file-list="false">
                <el-button class="ml10" type="primary" size="mini" @click="btnAttachmentUpload">
                    {{col.btnUpLoad}}
                </el-button>
            </el-upload>-->
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{ExaminationRecord.Remarks+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.Remarks"
                                          autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row type="flex" justify="end">
               
                <el-form-item>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>-->
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="onBack">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>

    </div>
    <script type="text/javascript">

        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                //业务表单内容
                CBS_Lists:[],
                Form: {
                    id: guidEmpty,
                    trainRecordId:'',
                    cbsListId:'',
                    //TrainingCoursewareName: '',
                    isQualified: '',
                    examinationDate: '',
                    degreeOfDifficulty: '',
                    examiner: '',
                    ExaminationCategory: '',
                    fraction: '',
                    attachmentId: '',
                    attachmentName:'',
                    Remarks: ''
                },
                TrainingCoursewareName: [],
                IsPassed: [{ key: '合格', value: '合格' },
                    { key: '不合格', value: '不合格' }],
                DegreeOfDifficulty: [{ key: '简单', value: '简单' },
                    { key: '一般', value: '一般' },
                    { key: '困难', value: '困难' },
                    { key: '极难', value: '极难' }],
                ExaminationCategory: [],
                Examiner: [],
                sex: [],
                //表单验证
                rules: {
                    examiner: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(2, 5), message: verification.StringLengthAtoB.m.format(2, 5), trigger: 'blur' }
                    ],
                    ExaminationCategory: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ],
                    trainRecordId: [
                        verification.NotNull
                    ],
                    isQualified: [
                        verification.NotNull
                    ],
                    degreeOfDifficulty: [
                        verification.NotNull
                    ],
                    examinationDate: [
                        verification.NotNull
                    ]
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/CBS_ExamRecord/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/CBS_ExamRecord/get?id=' + this.id);
                },
                onBack: function () {
                    parent.app.ListItem.dialogVisible = false;
                },
                handleChange: function (value) {
                    console.log(value);
                },
                beforeupload: function (file) {
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将文件名称赋值到label上
                    this.labelUpload = file.name;
                    const extension = testmsg === 'xls'
                    const extension2 = testmsg === 'xlsx'
                    const isLt2M = file.size / 1024 / 1024 < 10

                    if (!extension && !extension2) {
                        this.$message({
                            message: '上传文件只能是 xls、xlsx格式!',
                            type: 'warning'
                        });
                    }
                    if (!isLt2M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt2M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt2M
                },
                //上传附件文件的校验
                fileAttachmentUploadbeforeupload: function (file) {
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将附件名赋值到label上
                    this.Form.Annex = file.name;
                    const extension = testmsg === 'rar'
                    const extension2 = testmsg === 'zip'
                    const isLt2M = file.size / 1024 / 1024 < 10
                    if (!extension && !extension2) {
                        this.$message({
                            message: '上传文件只能是 rar、zip格式!',
                            type: 'warning'
                        });
                    }
                    if (!isLt2M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt2M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt2M
                }, btnAttachmentUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.fileAttachmentUpload != uploadText) {
                        this.$refs.Attachmentupload.clearFiles();
                        this.fileAttachmentUpload = file.name;
                    }
                    else {

                    }
                    this.$refs.Attachmentupload.submit();
                },
                submitFileListUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.labelUpload != uploadText) {
                        this.$refs.Fileupload.clearFiles();
                        this.labelUpload = file.name;
                    }
                    else {

                    }
                    //this.$refs.upload.submit();
                },
                handleRemove: function (file) {
                    console.log(file);
                },
                handlePreview: function (file) {
                    console.log(file.name);
                    window.open(file.url)
                },
                //初始化承包商下拉框
                getCBS_List: function () {
                    var mythis = this;

                    myAjax("post", mythis, '/api/CBS_List/GetList', { model: { status: '', CreateFactory: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.CBS_Lists = response.data.pageData;
                        //console.log('h1', response.data.pageData);
                    }, false);

                }, 
                //培训记录
                getCBS_TrainRecord: function() {
                    var mythis = this;

                    myAjax("post", mythis, '/api/CBS_TrainRecord/GetList', { model: {  CreateFactory: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.TrainingCoursewareName = response.data.pageData;
                        //console.log('h1', response.data.pageData);
                    }, false);

                },
                postChange2: function (val) {
                    var mythis = this;
                    //加载参与人 下拉
                    myAjax("post", mythis, '/api/CBS_User/GetList', { model: { cbsListId: val, CreateFactory: null }, offset: 0, limit: 100 }, function (response) {
                        mythis.Examiner = response.data.pageData;
                        //console.log('h1', response.data.pageData);
                    }, false);

                },
                //上传附件文件的校验
                beforeUpload: function (file) {
                    const isJPG = file.type === 'image/jpeg';
                    const isPNG = file.type === 'image/png';
                    const isLt2M = file.size / 1024 / 1024 < 2;
                    //if (!isJPG && !isPNG) {
                    //    this.$message.error('仅可上传 JPG和PNG 格式!');
                    //}
                    if (!isLt2M) {
                        this.$message.error('上传图片大小不能超过 2MB!');
                    }
                    return isLt2M; //(isJPG || isPNG) && 
                },
                //上传成功后执行
                successUpLoad: function (res, file) {
                    var data = res.data;//成功后的业务数据
                    var fileModel = data[0];//第一个文件对象
                    //var d = new Date();
                    this.Form.attachmentId = fileModel.id;
                    this.Form.attachmentName = file.name;
                    //this.Form.cbs_list.cbS_ListAttachments.push({
                    //    attachment: fileModel.id,
                    //    path: downLoadPath(fileModel.id),
                    //    name: file.name,
                    //    cbS_ListId: this.id,
                    //    uploadTime: new Date(d.setHours(d.getHours() + 8)).toJSON().substr(0, 19).replace('T', ' '),
                    //    uploadUser: this.Form.sysUser.id,
                    //    sysUser: {
                    //        sysUserInfor: { name: this.Form.sysUser.name, }
                    //    }
                    //});
                },
            },
            mounted: function () {
                //this.TrainingCoursewareName = getDicData('54');
                //this.IsPassed = getDicData('57');
                //this.DegreeOfDifficulty = getDicData('55');
                //this.ExaminationCategory = getDicData('139');
                //this.Examiner = getDicData('09');
                this.getCBS_TrainRecord();
                this.getCBS_List();
                this.id = getUrlParam("id");
                this.getData();
            }
        });
    </script>
</body>

</html>